import Mock from "mockjs";
import nodes from "../data/nodes";
import { getRandomItems } from "../util/utils";
export default {
  async save(ctx) {
    const params = ctx.request.body;
    ctx.body = {
      code: "0",
      data: null,
      msg: "Success",
      errMsg: null,
    };
  },
  async page(ctx: any) {
    const params = ctx.request.body;
    const list = Mock.mock({
      "list|30": [
        {
          "id|+1": 0,
          "version|1-100": 0,
          createTime: "@datetime",
          updateTime: "@datetime",
          updateUserCode: "@name",
          updateUserName: "@name",
          createUserCode: "@name",
          createUserName: "@name",
          tenantCode: "annto",
          categoryName: "@ctitle(6,10)",
          categoryCode: /\d{5,10}/,
          costTypeCode: /\d{5,10}/,
          costTypeName: "@ctitle(6,10)",
          "enableFlag|0-1": 0, // 0失效 1生产
        },
      ],
      offset: 0,
      pageNo: params.pageNo,
      pageSize: params.pageSize,
      totalCount: 10000,
      totalPage: 10000,
    });

    ctx.body = {
      code: "0",
      data: list,
      msg: "Success",
      errMsg: null,
    };
  },
  getAllProcess(ctx: any) {
    ctx.body = {
      code: "0",
      data: [
        {
          processCode: "QUOTE250306000046",
          processName: "器具回收",
        },
        {
          processCode: "QUOTE250306000042",
          processName: "主机厂卸货入库",
        },
        {
          processCode: "QUOTE250306000038",
          processName: "短驳配送",
        },
        {
          processCode: "QUOTE250306000036",
          processName: "装车",
        },
        {
          processCode: "QUOTE250306000032",
          processName: "打包出库",
        },
        {
          processCode: "QUOTE250306000028",
          processName: "分拣齐套",
        },
        {
          processCode: "QUOTE250306000024",
          processName: "创单",
        },
        {
          processCode: "QUOTE250306000022",
          processName: "存储",
        },
        {
          processCode: "QUOTE250306000012",
          processName: "VMI 卸货入库",
        },
      ],
      msg: "Success",
      errMsg: null,
    };
  },
  getNodes(ctx: any) {
    const params = ctx.request.body;
    console.log(params);
    ctx.body = {
      code: "0",
      data: nodes.filter((item: any) => {
        if (item.processCode === params.processCode) {
          return true;
        }
        return false;
      }),
      msg: "Success",
      errMsg: null,
    };
  },
};
